package algorithm;

import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        //int[] table = {38,26,97,19,66,1,5,49,1,2,3,5,2,3};
        //Scanner sc = new Scanner(System.in);
        String str = "38,26,97,19,66,1,5,49,1,2,3,5,2,3";//sc.nextLine();
        //int data = sc.nextInt();

        String[] strArr = str.split(",");
        int[] table = new int[strArr.length];
        for(int i=0;i<strArr.length;i++){
            table[i] = Integer.parseInt(strArr[i]);
        }
        quickSort(table);
        System.out.println(Arrays.toString(table));
    }
    public static void quickSort(int[] table) {
        quickSort(table,0,table.length-1);

    }
    public static void quickSort(int[] table, int low, int high) {
        if (low < high){
            int i=low,j=high;
            int vot = table[i];
            while (i!=j){
                while (i<j && vot<=table[j])
                    j--;
                if(i<j){
                    table[i] = table[j];
                    i++;
                }
                while(i<j && table[i]<vot)
                    i++;
                if(i<j){
                    table[j] = table[i];
                    j--;
                }
            }
            table[i] = vot;
            quickSort(table,low,j-1);
            quickSort(table,i+1,high);
        }
    }
}
